import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* Router Modules */
// import componentsRouter from './modules/components'
// import chartsRouter from './modules/charts'
// import tableRouter from './modules/table'
// import nestedRouter from './modules/nested'

/**

*注意:子菜单只在路由子菜单时出现。长度在= 1

*详情见:https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html

＊

*隐藏:true，如果设置为true，项目将不显示在侧边栏(默认为false)

*如果设置为true，将始终显示根菜单

*如果没有设置alwaysShow，当item有多个子路由时，

*它将变成嵌套模式，否则不显示根菜单

* redirect: noRedirect如果设置了noRedirect则在breadcrumb中没有重定向

* name:'router-name'，该名称被&lt;(必须设置! !)

* meta: {

  角色:['admin'，'editor']控制页面角色(你可以设置多个角色)

  标题:' Title '显示在侧边栏和面包屑中的名称(建议设置)

  图标:'svg-name'/'el-icon-x'显示在侧边栏的图标

  noCache: true如果设置为true，页面将不会被缓存(默认为false)

  Affix: true如果设置为true，标签将被添加到标签视图中

  面包屑:false，如果设置为false，项目将隐藏在面包屑中(默认为true)

  activeMenu: '/example/list'如果设置了path，侧边栏会突出显示你设置的路径

  *｝

* /

/**
 * 常规路由
 * 没有权限要求的基页所有角色均可访问
 */
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: '首页', icon: 'dashboard', affix: true }
      }
    ]
  }

]

/**
 * 异步路由Routes
 * 需要根据用户角色动态加载的路由
 */
export const asyncRoutes = [
  {
    path: '/image',
    component: Layout,
    children: [
      {
        path: 'index',
        component: () => import('@/views/image/index'),
        name: 'Image',
        meta: { title: '七牛资源', icon: 'el-icon-picture-outline-round', noCache: true }
      }
    ]
  },
  {
    path: '/localrow',
    component: Layout,
    children: [
      {
        path: 'index',
        component: () => import('@/views/localrow/index'),
        name: 'Localrow',
        meta: { title: '本地资源', icon: 'el-icon-camera-solid', noCache: true }
      }
    ]
  },
  {
    path: '/slide',
    component: Layout,
    children: [
      {
        path: 'index',
        component: () => import('@/views/slide/index'),
        name: 'Slide',
        meta: { title: '轮播管理', icon: 'el-icon-picture', noCache: true }
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    children: [
      {
        path: 'index',
        component: () => import('@/views/user/index'),
        name: 'User',
        meta: { title: '用户管理', icon: 'user', noCache: true }
      }
    ]
  },
  {
    path: '/auth',
    component: Layout,
    redirect: 'noRedirect',
    meta: { title: '权限管理', icon: 'el-icon-s-tools' },
    children: [
      {
        path: 'role',
        component: () => import('@/views/role/index'),
        name: 'RoleList',
        meta: { title: '角色管理' ,icon: 'el-icon-user-solid', noCache: true}
      },
      {
        path: 'admin',
        component: () => import('@/views/admin/index'),
        name: 'AdminList',
        meta: { title: '后台用户',icon: 'el-icon-user', noCache: true }
      }
    ]
  },
  {
    path: '/dev',
    component: Layout,
    redirect: 'noRedirect',
    meta: { title: '开发者配置', icon: 'el-icon-discover' },
    children: [
      {
        path: 'api',
        component: () => import('@/views/api/index'),
        name: 'ApiList',
        meta: { title: '接口管理' }
      }

    ]
  },
  {
    path: '/config',
    component: Layout,
    redirect: 'noRedirect',
    meta: { title: '微信服务', icon: 'el-icon-chat-dot-round' },
    children: [
      {
        path: 'log',
        component: () => import('@/views/subscribe/index'),
        name: 'SubscribeList',
        meta: { title: '发送日志', icon: 'el-icon-s-promotion', noCache: true }
      },
      {
        path: 'thing',
        component: () => import('@/views/config/index'),
        name: 'thingList',
        meta: { title: '订阅配置', icon: 'el-icon-s-opportunity', noCache: true }
      },
      {
        path: 'event',
        component: () => import('@/views/event/index'),
        name: 'eventList',
        meta: { title: '微信事件', icon: 'el-icon-chat-line-square', noCache: true }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
